﻿using System.Diagnostics.Contracts;
using System.Text.RegularExpressions;

namespace CodePlex.Diagnostics.Contracts.Conditions
{
	public static partial class Condition
	{
		[Pure]
    public static bool IsNullOrEmpty(this string value)
		{
			Contract.Ensures(Contract.Result<bool>() == string.IsNullOrEmpty(value));

			return string.IsNullOrEmpty(value);
		}

		[Pure]
    public static bool IsEmpty(this string value)
		{
      Contract.Requires(!value.IsNull());
      Contract.Ensures(Contract.Result<bool>() == (value.Length == 0));

			return value.Length == 0;
		}

		[Pure]
    public static bool IsMatch(this string input, string pattern)
		{
			Contract.Requires(!input.IsNull());
			Contract.Requires(!pattern.IsNull());

			return new Regex(pattern).IsMatch(input);
		}

		[Pure]
		public static bool IsMatch(this string input, string pattern, RegexOptions options)
		{
			Contract.Requires(!input.IsNull());
			Contract.Requires(!pattern.IsNull());

			return new Regex(pattern, options).IsMatch(input);
		}
	}
}
